package com.dev.tools.util;

import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.util.Arrays;

public class EachFile {
    public static void main(String[] args) {

        File dir = getFile("E:\\workFile\\微机保护");
        traversalFile("E:\\workFile\\微机保护");
        // It is also possible to filter the list of returned files.
        // This example does not return any files that start with `.'.
        FilenameFilter filter = (dir1, name) -> !name.startsWith(".");
        String[] children = dir.list(filter);
        System.out.println(Arrays.toString(children));
        // The list of files can also be retrieved as File objects
        File[] files = dir.listFiles();
        // This filter only returns directories
        FileFilter fileFilter = File::isDirectory;
        files = dir.listFiles(fileFilter);
        System.out.println(Arrays.toString(files));

    }

    public static void traversalFile(String pathName) {
        File dir = getFile(pathName);
        String[] children = dir.list();
        if (children != null) {
            for (String filename : children) {
                // Get filename of file or directory
                System.out.println(filename);
            }
        }
    }

    public static File getFile(String pathName) {
        return new File(pathName);
    }
}
